<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.microsoft.com/MicrosoftNotificationServices/ApplicationDefinitionFileSchema">
	<!-- Version -->
	<!-- History -->
	<Database>
		<DatabaseName>ServiceProviderRegister</DatabaseName>
		<SchemaName>CN</SchemaName>
	</Database>
	<EventClasses>
		<EventClass>
			<EventClassName>ServiceProviderChangesData</EventClassName>
			<Schema>
				<Field>
					<FieldName>DestinationProviderID</FieldName>
					<FieldType>varchar(10)</FieldType>
					<FieldTypeMods>not null</FieldTypeMods>        
				</Field>
			</Schema>
			<IndexSqlSchema>
				<SqlStatement>
					CREATE INDEX SPIndex 
					ON CN.ServiceProviderChangesData ( DestinationProviderID );
				</SqlStatement>
			</IndexSqlSchema>
		</EventClass>
		<EventClass>
			<EventClassName>MessageTypeChangesData</EventClassName>
			<Schema>
				<Field>
					<FieldName>DestinationProviderID</FieldName>
					<FieldType>varchar(10)</FieldType>
					<FieldTypeMods>not null</FieldTypeMods>
        </Field>
			</Schema>
			<IndexSqlSchema>
				<SqlStatement>
					CREATE INDEX MTIndex 
					ON CN.MessageTypeChangesData ( DestinationProviderID );
				</SqlStatement>
			</IndexSqlSchema>
		</EventClass>
	</EventClasses>
	<!-- Subscription Classes -->
	<SubscriptionClasses>
		<SubscriptionClass>
			<SubscriptionClassName>ServiceProviderSubscription</SubscriptionClassName>
			<Schema>
				<Field>
					<FieldName>DeviceName</FieldName>
					<FieldType>nvarchar(255)</FieldType>
					<FieldTypeMods>not null</FieldTypeMods>
				</Field>
				<Field>
					<FieldName>SubscriberLocale</FieldName>
					<FieldType>nvarchar(10)</FieldType>
					<FieldTypeMods>not null</FieldTypeMods>
				</Field>
				<Field>
					<FieldName>ServiceProviderID</FieldName>
					<FieldType>varchar(10)</FieldType>
					<FieldTypeMods>not null</FieldTypeMods>
				</Field>
			</Schema>
			<IndexSqlSchema>
				<SqlStatement>
					CREATE INDEX PSubIndex
					ON CN.ServiceProviderSubscription (ServiceProviderID)
				</SqlStatement>
			</IndexSqlSchema>
			<EventRules>
				<EventRule>
					<RuleName>ServiceProviderUpdatedEventRule</RuleName>
					<EventClassName>ServiceProviderChangesData</EventClassName>
					<Action>
            INSERT INTO CN.NotificationAlerts(SubscriberID, DeviceName, SubscriberLocale, ServiceProviderID, changedElement)
            SELECT s.SubscriberId, s.DeviceName, s.SubscriberLocale, e.DestinationProviderID, 'serviceprovider'
            FROM CN.ServiceProviderChangesData e, CN.ServiceProviderSubscription s
            WHERE e.DestinationProviderID = s.ServiceProviderID
          </Action>
				</EventRule>
				<EventRule>
					<RuleName>MessageTypeUpdateEventRule</RuleName>
					<EventClassName>MessageTypeChangesData</EventClassName>
					<Action>
					  INSERT INTO CN.NotificationAlerts(SubscriberID, DeviceName, SubscriberLocale, ServiceProviderID, changedElement)
					  SELECT s.SubscriberId, s.DeviceName, s.SubscriberLocale, e.DestinationProviderID, 'messagetype'
					  FROM CN.MessageTypeChangesData e, CN.ServiceProviderSubscription s
					  WHERE e.DestinationProviderID = s.ServiceProviderID
					</Action>
				</EventRule>
			</EventRules>
		</SubscriptionClass>
	</SubscriptionClasses>
	<!-- Notification Classes -->
	<NotificationClasses>
		<NotificationClass>
			<NotificationClassName>NotificationAlerts</NotificationClassName>
			<Schema>
				<Fields>
					<Field>
						<FieldName>ServiceProviderID</FieldName>
						<FieldType>nvarchar(35)</FieldType>
					</Field>
          <Field>
            <FieldName>ChangedElement</FieldName>
            <FieldType>varchar(50)</FieldType>
          </Field>
				</Fields>
			</Schema>
			<Protocols>
				<Protocol>
					<ProtocolName>HCEProtocol</ProtocolName>
				</Protocol>
			</Protocols>
			<ContentFormatter>
				<ClassName>XsltFormatter</ClassName>
        <Arguments>
          <Argument>
            <Name>XsltBaseDirectoryPath</Name>
            <Value>%BaseDirectory%</Value>
          </Argument>
          <Argument>
            <Name>XsltFileName</Name>
            <Value>identity.xsl</Value>
          </Argument>
          <Argument>
            <Name>DisableEscaping</Name>
            <Value>True</Value>
          </Argument>
        </Arguments>
			</ContentFormatter>
		</NotificationClass>
	</NotificationClasses>
	<Providers>
		<NonHostedProvider>
			<ProviderName>ServiceProviderSPEventProvider</ProviderName>
		</NonHostedProvider>
	</Providers>
	<!-- Generator Settings -->
	<Generator>
		<SystemName>%SystemName%</SystemName>
	</Generator>
	<!-- Distributor Settings -->
	<Distributors>
		<Distributor>
			<SystemName>%SystemName%</SystemName>
		</Distributor>
	</Distributors>
	<ApplicationExecutionSettings>
		<QuantumDuration>PT15S</QuantumDuration>
		<DistributorLogging>
			<LogBeforeDeliveryAttempts>false</LogBeforeDeliveryAttempts>
			<LogStatusInfo>false</LogStatusInfo>
			<LogNotificationText>false</LogNotificationText>
		</DistributorLogging>
		<Vacuum>
			<RetentionAge>P1D</RetentionAge>
			<VacuumSchedule>
				<Schedule>
					<StartTime>23:00:00</StartTime>
					<Duration>P0DT02H00M00S</Duration>
				</Schedule>
			</VacuumSchedule>
		</Vacuum>
	</ApplicationExecutionSettings>
</Application>
